package com.csw.android.localplayer.ui

import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.csw.android.dev_utils.ui.databinding.DataBindingActivity
import com.csw.android.localplayer.R
import com.csw.android.localplayer.databinding.UiTestBinding
import com.csw.android.player.base.MediaInfo

class TestActivity : DataBindingActivity<UiTestBinding>() {
    private var pickVideo: ActivityResultLauncher<String>? = null
    override fun getContentViewID() = R.layout.ui_test

    override fun initListener() {
        super.initListener()
        pickVideo = registerForActivityResult(ActivityResultContracts.GetContent()) {
            it?.let {
                dataBinding?.videoView?.run {
                    mediaInfo = MediaInfo(it.toString(), it, it)
                    play()
                }
            }
        }
        dataBinding?.selectVideo?.setOnClickListener {
            pickVideo?.launch("video/*")
        }
    }
}